home *** CD-ROM | disk | FTP | other *** search
/ Hottest 6 / Hottest 6 (1996)(PDSoft)[!].iso / software / programming / c / sipp / demo / structure.c < prev    next >
Encoding:
C/C++ Source or Header  |  1978-11-24  |  3.2 KB  |  144 lines

  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. #include <sipp.h>
  5. #include <primitives.h>
  6. #include <shaders.h>
  7.  
  8.  
  9. #define SPHERERES 40
  10. #define CYLRES    40
  11.  
  12. #define SIGNBIT(bit, i)   (((i >> bit) & 1) ? -1.0 : 1.0)
  13.  
  14. Surf_desc surf = {
  15.     0.4,
  16.     0.7, 
  17.     0.1, 
  18.     {0.8, 0.6, 0.3}, 
  19.     {1.0, 1.0, 1.0}
  20.     };
  21.     
  22. Bumpy_desc bumpy_surf = {
  23.     basic_shader, 
  24.     &surf, 
  25.     14.0, 
  26.     FALSE, 
  27.     TRUE
  28. };
  29.  
  30. extern char *optarg;
  31.  
  32. main(argc, argv)
  33.     int    argc;
  34.     char **argv;
  35. {
  36.     Object  *sphere;
  37.     Object  *cyl;
  38.     Object  *structure;
  39.     FILE    *fp ;
  40.     Surf_desc cyl_surf;
  41.     int      i;
  42.  
  43.     char    *imfile_name;
  44.     int      mode;
  45.     int      c;
  46.     int      size;
  47.  
  48.     imfile_name = "structure.ppm";
  49.     mode = PHONG;
  50.     size = 256;
  51.  
  52.     while ((c = getopt(argc, argv, "pgfls:")) != EOF) {
  53.         switch (c) {
  54.           case 'p':
  55.             mode = PHONG;
  56.             imfile_name = "structure.ppm";
  57.             break;
  58.  
  59.           case 'g':
  60.             mode = GOURAUD;
  61.             imfile_name = "structure.ppm";
  62.             break;
  63.  
  64.           case 'f':
  65.             mode = FLAT;
  66.             imfile_name = "structure.ppm";
  67.             break;
  68.  
  69.           case 'l':
  70.             mode = LINE;
  71.             imfile_name = "structure.pbm";
  72.             break;
  73.  
  74.           case 's':
  75.             size = atoi(optarg);
  76.             break;
  77.         }
  78.     }
  79.  
  80.     sipp_init();
  81.  
  82.     lightsource_create(1.0, 1.0, 1.0, 0.9, 0.9, 0.9, LIGHT_DIRECTION);
  83.     lightsource_create(-1.0, -1.0, 0.5, 0.4, 0.4, 0.4, LIGHT_DIRECTION);
  84.  
  85.     cyl_surf.ambient = 0.5;
  86.     cyl_surf.specular = 0.4;
  87.     cyl_surf.c3 = 0.3;
  88.     cyl_surf.color.red = 0.5;
  89.     cyl_surf.color.grn = 0.6;
  90.     cyl_surf.color.blu = 0.8;
  91.     cyl_surf.opacity.red = 1.0;
  92.     cyl_surf.opacity.grn = 1.0;
  93.     cyl_surf.opacity.blu = 1.0;
  94.     
  95.     structure = object_create();
  96.  
  97.     sphere = sipp_sphere(1.0, SPHERERES, &bumpy_surf, bumpy_shader, WORLD);
  98.     for (i = 0; i < 8; i++) {
  99.         if (i) {
  100.             sphere = object_instance(sphere);
  101.         }
  102.         object_move(sphere, 2.0 * SIGNBIT(2, i), 2.0 * SIGNBIT(1, i), 
  103.                     2.0 * SIGNBIT(0, i));
  104.         object_add_subobj(structure, sphere);
  105.     }
  106.  
  107.     cyl = sipp_cylinder(0.25, 4.0, CYLRES, &cyl_surf, basic_shader, WORLD);
  108.     for (i = 0; i < 4; i++) {
  109.         if (i) {
  110.             cyl = object_instance(cyl);
  111.         }
  112.         object_move(cyl, 2.0 * SIGNBIT(1, i), 2.0 * SIGNBIT(0, i), 0.0);
  113.         object_add_subobj(structure, cyl);
  114.     }
  115.     for (i = 0; i < 4; i++) {
  116.         cyl = object_instance(cyl);
  117.         object_rot_x(cyl, M_PI / 2.0);
  118.         object_move(cyl, 2.0 * SIGNBIT(1, i), 0.0, 2.0 * SIGNBIT(0, i));
  119.         object_add_subobj(structure, cyl);
  120.     }
  121.     for (i = 0; i < 4; i++) {
  122.         cyl = object_instance(cyl);
  123.         object_rot_y(cyl, M_PI / 2.0);
  124.         object_move(cyl, 0.0, 2.0 * SIGNBIT(1, i), 2.0 * SIGNBIT(0, i));
  125.         object_add_subobj(structure, cyl);
  126.     }
  127.     
  128.     object_add_subobj(sipp_world, structure);
  129.  
  130.     camera_position(sipp_camera, 10.0, -5.0, 15.0);
  131.     camera_look_at(sipp_camera, 0.0, 0.0, 0.0);
  132.     camera_up(sipp_camera, 0.0, 0.0, 1.0);
  133.     camera_focal(sipp_camera, 0.25);
  134.  
  135.     printf("Rendering, wait...");
  136.     fflush(stdout);
  137.  
  138.     fp = fopen(imfile_name, "w");
  139.     render_image_file(size, size, fp, mode, 2);
  140.     printf("Done.\n");
  141.  
  142.     exit(0);
  143. }
  144.